/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * SmartBoard.java
 *
 * Created on May 29, 2009, 9:54:48 AM
 */

package graphboard;

import core.TreeComponent;

/**
 *
 * @author anand
 */
public class SmartBoard extends javax.swing.JPanel {

    /** Creates new form SmartBoard */
    public int state;

    public SmartBoard() {
        state = TreeComponent.DRAG;
        initComponents();
        init();
    }

    public TreeComponent getTree(){
        return treeComponent1;
    }

    public void init(){
        treeComponent1.addKeyListener(treeComponent1);
		treeComponent1.addMouseListener(treeComponent1);
		treeComponent1.addMouseMotionListener(treeComponent1);
    }

    public void updateBoxes(){
        jRadioButton1.setSelected(state == TreeComponent.DRAG);
        jRadioButton2.setSelected(state == TreeComponent.LINK);
        jRadioButton3.setSelected(state == TreeComponent.CREATENEU || state == TreeComponent.CREATENEG || state == TreeComponent.CREATEPOS);
        jButton1.setText(core.Main.running? "Pause" : "Run");
        treeComponent1.state = state;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jComboBox1 = new javax.swing.JComboBox();
        treeComponent1 = new core.TreeComponent();
        jSeparator1 = new javax.swing.JSeparator();
        jRadioButton1 = new javax.swing.JRadioButton();
        jRadioButton2 = new javax.swing.JRadioButton();
        jRadioButton3 = new javax.swing.JRadioButton();
        jLabel1 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();

        jComboBox1.setFont(new java.awt.Font("AppleGothic", 0, 13)); // NOI18N
        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Neutral", "Positive", "Negative" }));
        jComboBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox1ActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout treeComponent1Layout = new org.jdesktop.layout.GroupLayout(treeComponent1);
        treeComponent1.setLayout(treeComponent1Layout);
        treeComponent1Layout.setHorizontalGroup(
            treeComponent1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 823, Short.MAX_VALUE)
        );
        treeComponent1Layout.setVerticalGroup(
            treeComponent1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 476, Short.MAX_VALUE)
        );

        jRadioButton1.setFont(new java.awt.Font("AppleGothic", 0, 13));
        jRadioButton1.setText("Drag");
        jRadioButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton1ActionPerformed(evt);
            }
        });

        jRadioButton2.setFont(new java.awt.Font("AppleGothic", 0, 13));
        jRadioButton2.setText("Link");
        jRadioButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton2ActionPerformed(evt);
            }
        });

        jRadioButton3.setFont(new java.awt.Font("AppleGothic", 0, 13));
        jRadioButton3.setText("Node");
        jRadioButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton3ActionPerformed(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Apple LiGothic", 1, 20));
        jLabel1.setText("Create");

        jButton1.setText("Pause");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                .add(treeComponent1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                        .add(org.jdesktop.layout.GroupLayout.LEADING, jRadioButton1)
                        .add(org.jdesktop.layout.GroupLayout.LEADING, jRadioButton2)
                        .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                            .add(jLabel1)
                            .add(jRadioButton3))
                        .add(org.jdesktop.layout.GroupLayout.LEADING, jComboBox1, 0, 93, Short.MAX_VALUE))
                    .add(layout.createSequentialGroup()
                        .add(12, 12, 12)
                        .add(jButton1))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(jRadioButton1)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jLabel1)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jRadioButton2)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jRadioButton3)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jComboBox1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jButton1)
                .addContainerGap(297, Short.MAX_VALUE))
            .add(treeComponent1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jRadioButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton1ActionPerformed
        state = TreeComponent.DRAG;
        updateBoxes();
    }//GEN-LAST:event_jRadioButton1ActionPerformed

    private void jRadioButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton2ActionPerformed
        state = TreeComponent.LINK;
        updateBoxes();
    }//GEN-LAST:event_jRadioButton2ActionPerformed

    private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox1ActionPerformed
        state = (jComboBox1.getSelectedIndex() == 0? TreeComponent.CREATENEU:
                (jComboBox1.getSelectedIndex() == 1 ? TreeComponent.CREATEPOS :
                                                        TreeComponent.CREATENEG));
        //System.out.println("XX " +jComboBox1.getSelectedIndex());
        updateBoxes();
    }//GEN-LAST:event_jComboBox1ActionPerformed

    private void jRadioButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton3ActionPerformed
        state = (jComboBox1.getSelectedIndex() == 0? TreeComponent.CREATENEU:
                (jComboBox1.getSelectedIndex() == 1 ? TreeComponent.CREATEPOS :
                                                        TreeComponent.CREATENEG));
        //System.out.println("XX " +jComboBox1.getSelectedIndex());
        updateBoxes();
        //TODO charge
    }//GEN-LAST:event_jRadioButton3ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        core.Main.running = !core.Main.running;
        updateBoxes();
    }//GEN-LAST:event_jButton1ActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JRadioButton jRadioButton1;
    private javax.swing.JRadioButton jRadioButton2;
    private javax.swing.JRadioButton jRadioButton3;
    private javax.swing.JSeparator jSeparator1;
    private core.TreeComponent treeComponent1;
    // End of variables declaration//GEN-END:variables

}
